package cn.gene.timeyan.ums.webapi.ums.controller;

import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.ums.dto.UserDetailAddDTO;
import cn.gene.timeyan.pojo.ums.vo.UserSimpleVO;
import cn.gene.timeyan.ums.service.IUserDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 用户详细（不常用）信息表 前端控制器*
 *
 * @author LWG
 * @date 2022/7/23 10:32
 * @since 1.0.0@gene.cn
 */
@RestController
@RequestMapping("/ums/userDetail")
@Api(tags="用户详情模块")
public class UserDetailController {
    /*@Autowired(required = false)
    private IUserDetailService userDetailService;
    @ApiOperation("情侣")
    @ApiImplicitParams({

            @ApiImplicitParam(value = "用户ID",name = "userId",dataType = "Long",
                    required = true),
            @ApiImplicitParam(value = "情侣ID",name = "loversId",dataType = "Long",
                    required = true),
    })
    @PostMapping("/lovers")
    public JsonResult attention(
            @RequestParam(value = "userId",defaultValue = "1L")Long userId,
            @RequestParam(value = "loversId",defaultValue = "2L") Long loversId
    ){
        if(userId==null||loversId==null) {
            return JsonResult.ok("数据不能为空");
        }
        userDetailService.getLoverState(userId, loversId);
        return JsonResult.ok("情侣互关成功");
    }*/

    @Autowired
    IUserDetailService iUserDetailService;

    @ApiOperation("获取用户积分")
    @GetMapping("/score/{userId}")
    public JsonResult<Integer> selectUserScore(@PathVariable("userId") Long userId){
        return iUserDetailService.selectUserScore(userId);
    }

    @PostMapping("/add-new")
    @ApiOperation("添加用户详情")
    public JsonResult<Void> addNew(@Validated @RequestBody UserDetailAddDTO userDetailAddDTO) {
        iUserDetailService.addnew(userDetailAddDTO);
        return JsonResult.ok();
    }
    @Autowired
    private IUserDetailService userDetailService;
    @RequestMapping("/{id}")
    @ApiOperation("获取用户简易信息")
    public JsonResult<UserSimpleVO> simpleInfo(@PathVariable("id") Long id ){
        UserSimpleVO simpleVO=userDetailService.selectUserCommentVOByUserId(id);
        return JsonResult.ok(simpleVO);
    }
    /**
     * 修改用户属性
     * @param userId
     * 下面这些是可以改的
     * @param nickname
     * @param gender
     * @param birthday
     * @param address
     * @param profession
     * @param school
     * @param hobby
     * @param introduction
     * @return 受影响行数
     */
    @PostMapping("/updateUserDetail")
    @ApiOperation("修改用户属性")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id",name="userId",example = "1"),
            @ApiImplicitParam(value = "用户昵称",name="nickname",example = "nm"),
            @ApiImplicitParam(value = "性别",name="gender",example = "1"),
            @ApiImplicitParam(value = "生日",name="birthday",example = "2016-06-19"),
            @ApiImplicitParam(value = "地址",name="address",example = "中国"),
            @ApiImplicitParam(value = "职业",name="profession",example = "灵活就业者"),
            @ApiImplicitParam(value = "学校",name="school",example = "加里敦"),
            @ApiImplicitParam(value = "爱好",name="hobby",example = "变大人"),
            @ApiImplicitParam(value = "介绍",name="introduction",example = "24岁事学生"),
    })//不知道为什么生日这条knife4j写不进去
    public JsonResult<Integer> updateUserDetail(Long userId,
                                                String nickname, String gender,
                                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday, String address,
                                                String profession, String school,
                                                String hobby, String introduction) {
        int row = iUserDetailService.updateUserDetailInformationService(userId,
                nickname, gender,
                birthday, address,
                profession, school,
                hobby, introduction);
        return JsonResult.ok(row);
    }


}
